Micron Document
🎖️GitЯра🎖️


Displaying Raw • Download

core/service/src/androidMain/kotlin/org/meshtastic/core/service/PersonIconFactory.kt 2d20cd8a4708e2ef66e98d5259f3a97ec93f240a (2d20cd8a) Text, 4.51 KB

T8b949e/*
* Copyright (c) 2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Tff7b72package T7ee787org.meshtastic.core.service

Tff7b72import T7ee787android.graphics.Canvas
Tff7b72import T7ee787android.graphics.Paint
Tff7b72import T7ee787androidx.core.graphics.createBitmap
Tff7b72import T7ee787androidx.core.graphics.drawable.IconCompat

T8b949e/**
* Renders avatar icons for [androidx.core.app.Person] icons in MessagingStyle notifications and for conversation
* shortcuts. Two shapes give conversations a recognizable identity at a glance:
* - a **wide pill** for people / direct messages (holds the node initial or short name), mirroring the in-app node
* chip, and
* - a **rounded square** for channels (holds the channel number),
*
* both filled with the caller-supplied colors (node colors for people, a channel-derived color for channels).
*/
Tff7b72internal Tff7b72object T56d364PersonIconFactory Tb4b4b4{

Tff7b72private Tff7b72const Tff7b72val Te6edf3ICON_SIZE Tff7b72= T79c0ff1T79c0ff2T79c0ff8
Tff7b72private Tff7b72const Tff7b72val Te6edf3TEXT_SIZE_RATIO Tff7b72= T79c0ff0.5f

T8b949e// Leave a margin so multi-character labels (e.g. a 4-char node short name) don't touch the edge.
Tff7b72private Tff7b72const Tff7b72val Te6edf3MAX_TEXT_WIDTH_RATIO Tff7b72= T79c0ff0.72f
Tff7b72private Tff7b72const Tff7b72val Te6edf3CORNER_RADIUS_RATIO Tff7b72= T79c0ff0.28f

T8b949e// Height of the people pill relative to the square canvas; the rest is transparent top/bottom margin so the pill
T8b949e// reads as a wide chip like the in-app node chip.
Tff7b72private Tff7b72const Tff7b72val Te6edf3PILL_HEIGHT_RATIO Tff7b72= T79c0ff0.56f

T8b949e// Corner radius of the people pill as a fraction of its height. Less than 0.5 (a full stadium) so it reads as a
T8b949e// rounded-rectangle chip like the M3 AssistChip, not a lozenge.
Tff7b72private Tff7b72const Tff7b72val Te6edf3PILL_CORNER_RATIO Tff7b72= T79c0ff0.3f

T8b949e/** Wide-pill avatar with a single uppercase initial taken from [name]. */
Tff7b72fun Td2a8ffcreateTb4b4b4(Te6edf3nameTb4b4b4: Tffa657StringTb4b4b4, Te6edf3backgroundColorTb4b4b4: Tffa657IntTb4b4b4, Te6edf3foregroundColorTb4b4b4: Tffa657IntTb4b4b4)Tb4b4b4: Te6edf3IconCompat Tff7b72=
Te6edf3renderTb4b4b4(Te6edf3firstInitialTb4b4b4(Te6edf3nameTb4b4b4)Tb4b4b4, Te6edf3backgroundColorTb4b4b4, Te6edf3foregroundColorTb4b4b4, Te6edf3rounded Tff7b72= Tff7b72falseTb4b4b4)

T8b949e/**
* Avatar showing a short [label] verbatim (e.g. a node's 4-character short name, or a channel number), auto-sized
* to fit. [rounded] draws a rounded square (channels) instead of the people pill.
*/
Tff7b72fun Td2a8ffcreateLabelTb4b4b4(Te6edf3labelTb4b4b4: Tffa657StringTb4b4b4, Te6edf3backgroundColorTb4b4b4: Tffa657IntTb4b4b4, Te6edf3foregroundColorTb4b4b4: Tffa657IntTb4b4b4, Te6edf3roundedTb4b4b4: Tffa657BooleanTb4b4b4)Tb4b4b4: Te6edf3IconCompat Tff7b72=
Te6edf3renderTb4b4b4(Te6edf3labelTb4b4b4.Te6edf3ifBlank Tb4b4b4{ Ta5d6ff"Ta5d6ff?Ta5d6ff" Tb4b4b4}Tb4b4b4, Te6edf3backgroundColorTb4b4b4, Te6edf3foregroundColorTb4b4b4, Te6edf3roundedTb4b4b4)

Tff7b72private Tff7b72fun Td2a8fffirstInitialTb4b4b4(Te6edf3nameTb4b4b4: Tffa657StringTb4b4b4)Tb4b4b4: Tffa657String Tff7b72=
Tff7b72if Tb4b4b4(Te6edf3nameTb4b4b4.Te6edf3isEmptyTb4b4b4(Tb4b4b4)Tb4b4b4) Ta5d6ff"Ta5d6ff?Ta5d6ff" Tff7b72else Tffa657StringTb4b4b4(Te6edf3CharacterTb4b4b4.Te6edf3toCharsTb4b4b4(Te6edf3nameTb4b4b4.Te6edf3codePointAtTb4b4b4(T79c0ff0Tb4b4b4)Tb4b4b4)Tb4b4b4)Tb4b4b4.Te6edf3uppercaseTb4b4b4(Tb4b4b4)

Tff7b72private Tff7b72fun Td2a8ffrenderTb4b4b4(Te6edf3textTb4b4b4: Tffa657StringTb4b4b4, Te6edf3backgroundColorTb4b4b4: Tffa657IntTb4b4b4, Te6edf3foregroundColorTb4b4b4: Tffa657IntTb4b4b4, Te6edf3roundedTb4b4b4: Tffa657BooleanTb4b4b4)Tb4b4b4: Te6edf3IconCompat Tb4b4b4{
Tff7b72val Te6edf3bitmap Tff7b72= Te6edf3createBitmapTb4b4b4(Te6edf3ICON_SIZETb4b4b4, Te6edf3ICON_SIZETb4b4b4)
Tff7b72val Te6edf3canvas Tff7b72= Te6edf3CanvasTb4b4b4(Te6edf3bitmapTb4b4b4)
Tff7b72val Te6edf3paint Tff7b72= Te6edf3PaintTb4b4b4(Te6edf3PaintTb4b4b4.Te6edf3ANTI_ALIAS_FLAGTb4b4b4)
Tff7b72val Te6edf3size Tff7b72= Te6edf3ICON_SIZETb4b4b4.Te6edf3toFloatTb4b4b4(Tb4b4b4)

Te6edf3paintTb4b4b4.Te6edf3color Tff7b72= Te6edf3backgroundColor
Tff7b72if Tb4b4b4(Te6edf3roundedTb4b4b4) Tb4b4b4{
Tff7b72val Te6edf3radius Tff7b72= Te6edf3ICON_SIZE Tff7b72* Te6edf3CORNER_RADIUS_RATIO
Te6edf3canvasTb4b4b4.Te6edf3drawRoundRectTb4b4b4(T79c0ff0fTb4b4b4, T79c0ff0fTb4b4b4, Te6edf3sizeTb4b4b4, Te6edf3sizeTb4b4b4, Te6edf3radiusTb4b4b4, Te6edf3radiusTb4b4b4, Te6edf3paintTb4b4b4)
Tb4b4b4} Tff7b72else Tb4b4b4{
T8b949e// Wide rounded-rectangle chip spanning the full width, vertically centered — matches the in-app node chip.
Tff7b72val Te6edf3pillHeight Tff7b72= Te6edf3size Tff7b72* Te6edf3PILL_HEIGHT_RATIO
Tff7b72val Te6edf3top Tff7b72= Tb4b4b4(Te6edf3size Tff7b72- Te6edf3pillHeightTb4b4b4) Tff7b72/ T79c0ff2f
Tff7b72val Te6edf3cap Tff7b72= Te6edf3pillHeight Tff7b72* Te6edf3PILL_CORNER_RATIO
Te6edf3canvasTb4b4b4.Te6edf3drawRoundRectTb4b4b4(T79c0ff0fTb4b4b4, Te6edf3topTb4b4b4, Te6edf3sizeTb4b4b4, Te6edf3size Tff7b72- Te6edf3topTb4b4b4, Te6edf3capTb4b4b4, Te6edf3capTb4b4b4, Te6edf3paintTb4b4b4)
Tb4b4b4}

Te6edf3paintTb4b4b4.Te6edf3color Tff7b72= Te6edf3foregroundColor
Te6edf3paintTb4b4b4.Te6edf3textAlign Tff7b72= Te6edf3PaintTb4b4b4.Te6edf3AlignTb4b4b4.Te6edf3CENTER
Te6edf3paintTb4b4b4.Te6edf3textSize Tff7b72= Te6edf3ICON_SIZE Tff7b72* Te6edf3TEXT_SIZE_RATIO
T8b949e// Shrink the text if it would overflow the icon (keeps 4-char short names inside the circle).
Tff7b72val Te6edf3measured Tff7b72= Te6edf3paintTb4b4b4.Te6edf3measureTextTb4b4b4(Te6edf3textTb4b4b4)
Tff7b72val Te6edf3maxWidth Tff7b72= Te6edf3ICON_SIZE Tff7b72* Te6edf3MAX_TEXT_WIDTH_RATIO
Tff7b72if Tb4b4b4(Te6edf3measured Tff7b72> Te6edf3maxWidthTb4b4b4) Te6edf3paintTb4b4b4.Te6edf3textSize Tff7b72*Tff7b72= Te6edf3maxWidth Tff7b72/ Te6edf3measured

Tff7b72val Te6edf3xPos Tff7b72= Te6edf3canvasTb4b4b4.Te6edf3width Tff7b72/ T79c0ff2f
Tff7b72val Te6edf3yPos Tff7b72= Te6edf3canvasTb4b4b4.Te6edf3height Tff7b72/ T79c0ff2f Tff7b72- Tb4b4b4(Te6edf3paintTb4b4b4.Te6edf3descentTb4b4b4(Tb4b4b4) Tff7b72+ Te6edf3paintTb4b4b4.Te6edf3ascentTb4b4b4(Tb4b4b4)Tb4b4b4) Tff7b72/ T79c0ff2f
Te6edf3canvasTb4b4b4.Te6edf3drawTextTb4b4b4(Te6edf3textTb4b4b4, Te6edf3xPosTb4b4b4, Te6edf3yPosTb4b4b4, Te6edf3paintTb4b4b4)

Tff7b72return Te6edf3IconCompatTb4b4b4.Te6edf3createWithBitmapTb4b4b4(Te6edf3bitmapTb4b4b4)
Tb4b4b4}
Tb4b4b4}

Served by rngit 1.5.0 - Generated in 0.06s